package com.quantum.remoting.proxy
{
	import flash.utils.Proxy;
	import flash.utils.flash_proxy;

	import hessian.mxml.HessianService;

	use namespace flash_proxy;

	dynamic public class RemoteHessianServiceProxy extends Proxy
	{
		private static var _services:Object={};

		private var _service:HessianService=null;

		private var _secure:Boolean;

		public static function getInstance(destination:String):RemoteHessianServiceProxy
		{
			var service:RemoteHessianServiceProxy=_services[destination] as RemoteHessianServiceProxy;
			if (service == null)
			{
				service=new RemoteHessianServiceProxy(PrivateConstructorToken, destination);
				_services[destination]=service;
			}

			return service;
		}

		public function RemoteHessianServiceProxy(token:Class, destination:String)
		{
			super();
			if (token != PrivateConstructorToken)
			{
				throw new Error("HessianRemoteService cannot be instantiated directly.");
			}

			_service=new HessianService();
			_service.destination="hessian/" + destination;
		}

		override flash_proxy function callProperty(name:*, ... rest):*
		{
			try
			{
				return _service.getOperation(name).send.apply(this, rest);
			}
			catch (e:Error)
			{
			}
		}

		override flash_proxy function getProperty(name:*):*
		{
			return _service.getOperation(name);
		}
	}
}

class PrivateConstructorToken
{
}